package org.jeecg.modules.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.CrawlSiteFeatureDoc;
import org.jeecg.modules.system.service.IScrawlSiteFeatureDocService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Author wt
 * @Date: 2024/9/26 9:31
 * @Description:
 */
@RestController
@RequestMapping("/sys/CrawlSiteFeatureDocCont")
@Slf4j
public class CrawlSiteFeatureDocController {
    @Autowired
    IScrawlSiteFeatureDocService iScrawlSiteFeatureDocService;


    /**
     * 分页列表查询
     *
     * @param crawlSiteFeatureDoc
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result<IPage<CrawlSiteFeatureDoc>> queryPageList(CrawlSiteFeatureDoc crawlSiteFeatureDoc,
                                                            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
        log.info("=====查询========"+crawlSiteFeatureDoc);
        Result<IPage<CrawlSiteFeatureDoc>> result = new Result<IPage<CrawlSiteFeatureDoc>>();
        Page<CrawlSiteFeatureDoc> page = new Page<CrawlSiteFeatureDoc>(pageNo, pageSize);
        IPage<CrawlSiteFeatureDoc> pageList = iScrawlSiteFeatureDocService.querySiteFeatureDoc(page, crawlSiteFeatureDoc);
        result.setSuccess(true);
        result.setResult(pageList);
        log.info("=====result========" + result);
        return result;
    }

    /**
     * 新增
     *
     * @param crawlSiteFeatureDoc
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Result<CrawlSiteFeatureDoc> add(@RequestBody CrawlSiteFeatureDoc crawlSiteFeatureDoc) {
        Result<CrawlSiteFeatureDoc> result = new Result<CrawlSiteFeatureDoc>();
        try {
            iScrawlSiteFeatureDocService.insertCrawlSiteFeatureDoc(crawlSiteFeatureDoc);
            result.success("添加成功！");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }

    /**
     * 编辑
     *
     * @param crawlSiteFeatureDoc
     * @return
     */
    @RequestMapping(value = "/edit", method = RequestMethod.PUT)
    public Result<CrawlSiteFeatureDoc> edit(@RequestBody CrawlSiteFeatureDoc crawlSiteFeatureDoc) {
        Result<CrawlSiteFeatureDoc> result = new Result<CrawlSiteFeatureDoc>();
            try {
                boolean ok = iScrawlSiteFeatureDocService.updateCrawlSiteFeatureDoc(crawlSiteFeatureDoc);
                if (ok) {
                    result.success("修改成功!");
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                result.error500("修改失败");
            }
        return result;
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    public Result<?> delete(@RequestParam(name = "id", required = true) Long id) throws IOException {
        iScrawlSiteFeatureDocService.deleteFeatureDoc(id);
        return Result.ok("删除成功");
    }


    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
    public Result<CrawlSiteFeatureDoc> deleteBatch(@RequestParam Long[] ids) {
        Result<CrawlSiteFeatureDoc> result = new Result<CrawlSiteFeatureDoc>();
        if (oConvertUtils.isEmpty(ids)) {
            result.error500("未选中变量！");
        } else {
            iScrawlSiteFeatureDocService.deleteBatchFeatureDoc(ids);
            result.success("删除成功!");
        }
        return result;
    }


}
